Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Adding C header files in C++ using extern "C" Generates error on 'static' type

I was working on a wayland compositor based on C++. My project uses wlroots which is a C Library. I have a set of header files in wlroots which i need to add to my C++ project. I used extern "C" to include c header files but it was showing errors on 'static' type.

/usr/local/include/wlr/render/wlr_renderer.h:72:27: error: expected primary-expression before ‘static’
   72 |         const float color[static 4], const float projection[static 9]);
      |                           ^~~~~~

Here is the sample code for reference :

#ifndef SERVER_HPP
#define SERVER_HPP

#include <wayland-server.h>

extern "C"
{
    #include <wlr/backend.h>
    #include <wlr/render/allocator.h>
    #include <wlr/render/wlr_renderer.h>
    #include <wlr/types/wlr_compositor.h>
};


class Server
{
    public:
        struct wl_display *wl_display;
        struct wl_event_loop *wl_event_loop;

        struct wlr_backend *backend;
        struct wlr_renderer *renderer;
        struct wlr_allocator *allocator;
        struct wlr_compositor *compositor;

    public:
        bool init();
        bool run();
        void terminate();
};

#endif

I did some digging and find out a way to fix it. by this method:

#define static

extern "C"
{
    #include <wlr/backend.h>
    #include <wlr/render/allocator.h>
    #include <wlr/render/wlr_renderer.h>
    #include <wlr/types/wlr_compositor.h>
};

#undef static

But i am not sure whether it will cause any issues in the future. This seems to be a hack method. Is there any better method to overcome this?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!